var Fnum = 0;
var JudgeS = false;
var Judge = false;
var ndm = $('.swiper-wrapper').children('div').length-3;
// /*控制窗口高度变化*/
$(window).resize(function(){
    minHeight = $(window).height();
    $('.r-team').height(minHeight);
    $('.t-pro').height(minHeight);
    $('.c-pro').height(minHeight);
    $('.f-us').height(minHeight);
})
$('.r-team').height($(window).height());
$('.t-pro').height($(window).height());
$('.c-pro').height($(window).height());
$('.f-us').height($(window).height());
//图片预加载
function preload(){
    var loadImg = []; // 创建一个数组，用于存储所有要预加载的图片路径
    // 通过push方法，将路径存储进去
    loadImg.push('images/rcity_30.png');
    loadImg.push('images/rcity_31.png');
    loadImg.push('images/rcity_32.png');
    loadImg.push('images/rcity_33.png');  
    var imgsNum = loadImg.length;      
    var nowNum = 0;
    var nowPercentage = 0; // 用于显示加载每一张图片之后，能够给出百分比     
    // 通过for循环，针对loadImg整个数组进行遍历
    for (var i = 0; i < imgsNum; i++) {         
        // 每一次i变化之后，都需要执行这样的内容 - 创建一个img对象，将img对象的src设置为相应的图片地址
        var newImg = new Image();
        newImg.src = loadImg[i];       
        // 每一张图片加载完成之后，都可以执行相应的功能，比如我们在制作loading条时，希望每加载一张图片之后就能够将当前进度显示出来，就可以用这个方法
        newImg.onload = (function() {
            // 一张图片加载完毕之后执行的功能 - 通常是为了控制进度条           
            nowNum++;
            nowPercentage = nowNum / imgsNum * 100;
        })();
    };
}preload()
//控制页面初始样式
$('.swiper-wrapper').children('div').eq(4).prevAll('div').css({
    'position': 'relative',
    'overflow': 'hidden',
    '-webkit-background-size': 'cover',
    '-moz-background-size': 'cover',
    'background-size': 'cover'
})
function box(){           
    if ($(window).width() <= 980) {
        $('.wrap>div').eq(ndm).prevAll('div').css({
            width : '980px'
        })
    }else{
        $('.wrap>div').eq(ndm).prevAll('div').css({
            width : '100%'
        })
    }
    if ($(window).height() <= 470) {
        $('.wrap>div').eq(ndm).prevAll('div').css({
            height : '470px'
        })
    }else{
        $('.wrap>div').eq(ndm).prevAll('div').css({
            height : '100%'
        })
    }
}box()

//获取URL地址，取出索引值
function UrlSearch() 
{
    var name,value; 
    var str = location.href; //取得整个地址栏
    var num = str.indexOf("?"); //取得?后面的参数
    str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ])
    var arr = str.split("&"); //各个参数放到数组里
    for(var i = 0;i < arr.length;i++){ 
        num = arr[i].indexOf("="); 
        if(num > 0){ 
            name = arr[i].substring(0,num);
            value = arr[i].substr(num + 1);
            this[name] = value;
            JudgeS = true;
        }
    }
}
var search = new UrlSearch();
var nid = search.nid;
//跳转页面滚动到相应的位置
if (JudgeS) {
    Fnum = nid;
    showH = $('.swiper-wrapper').children('div').height();
    resetA();
    JudgeS = false;
}
//页面滚动特效
var showH = $('.swiper-wrapper').children('div').height();
var lenA = $('.swiper-wrapper').children('div').length-1;                         
$(window).on('resize',function(){ 
    showH =  $('.swiper-wrapper').children('div').height();
    $('.swiper-wrapper').scrollTop(Fnum  * showH);
})   

//给页面绑定滑轮滚动事件 
function Page(){
    $('.swiper-wrapper').on('mousewheel DOMMouseScroll', function(e) {
        e = e.originalEvent || window.event.originalEvent;
        if ($('.swiper-wrapper').scrollTop() != Fnum *showH) {
            return
        };  
        scrollFunc(e)   
        reset(); 
    })      
}Page()
//点击上下键
$('.downbtn').on('click', function(){
    Fnum++;
    if (Fnum >= lenA) {
        Fnum = lenA;
        Fnum = Fnum - 2;
    };
    resetA();
})
//键盘上下键
$(document).keydown(function(e){
    if (e.keyCode == 38) {
        Judge = true;
        reset() 
    };
    if (e.keyCode == 40) {
        Judge = false;
        reset() 
    };     
})  
// //页面滚动
function reset(){ 
    if (Judge) {
        Fnum--;
    }else{
        Fnum++;
    }  
    if (Fnum > lenA - 1) {
        Fnum = lenA - 1;
    };
    if (Fnum < 0) {
        Fnum = 0;
    };
    resetA();
}
function resetA(){
    if (Fnum == lenA - 2) {
        $('.downbtn').css({
            'background' : 'url("images/rcity_06.png") no-repeat'
        })
    };
    if (Fnum == lenA - 1) {
        $('.downbtn').css({
            'background' : 'url("images/rcity_07.png") no-repeat'
        })
    };
    $('.wrap').stop().animate({
        'scrollTop' : Fnum  * showH
    }, 500) 
}
//判断滚动方向
function scrollFunc(e){        
    if (e.wheelDelta) {  //判断浏览器IE，谷歌滑轮事件               
        if (e.wheelDelta > 0) { //当滑轮向上滚动时  
            Judge = true;
        }  
        if (e.wheelDelta < 0) { 
            //当滑轮向下滚动时  
            Judge = false;
        }  
    } else if (e.detail) {  //Firefox滑轮事件  
        if (e.detail> 0) { //当滑轮向上滚动时  
            Judge = false;
        }  
        if (e.detail< 0) { //当滑轮向下滚动时  
           Judge = true; 
        }  
    }
} 
// 图片切换
$('.cselec li').on('mousemove', function(){
    var index = $(this).index()-2;
    $(this).addClass('c-show').siblings().removeClass('c-show');
    $('.c-show p').eq(index).addClass('c-link').siblings().removeClass('c-link');
})
$('.t-procn li').on('mousemove', function(){
    var index = $(this).index()-3;
    $(this).addClass('t-show').siblings().removeClass('t-show');
    $('.t-procn span').addClass('t-img').siblings().removeClass('t-img');
})
//鼠标移入切换效果
$('.nav li').on('click', function(){
    var indexB = $(this).index();
    Fnum = indexB;
    resetA();
})

$(window).resize(initFont);
function initFont() {
    var htmlWidth = $(window).width();
    if(htmlWidth >= 960) {
        $('html').css({
            'font-size' : 100 + 'px'
        })
    } else {
        $('html').css({
            'font-size' : 100 / 960 * htmlWidth + 'px'
        })
    }
}initFont();
